import 'package:my_flutter_core/models/method_callback.dart';
import 'package:my_flutter_core/utils/format_utils.dart';

class MethodRequest {
  MethodRequest({required this.methodName, this.params, this.callback});

  String methodName;
  Map<String, dynamic>? params;
  MethodCallback? callback;

  factory MethodRequest.fromJson(Map<String, dynamic> json) {
    return MethodRequest(
      methodName: json['methodName'].toString(),
      params: tryToConvert<Map<String, dynamic>>(
        json['params'],
        (p) => p as Map<String, dynamic>,
      ),
      callback: tryToConvert<MethodCallback>(
        json['callback'],
        (p) => MethodCallback.fromJson(p as Map<String, dynamic>),
      ),
    );
  }
}
